// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init()

// 云函数入口函数
exports.main = async (event, context) => {
 
  if (event.action == 'add') {
    return await cloud.database().collection('diagnose').add({
      data:{
        appoint:event.appoint,
        patientSituation:event.patientSituation,
        diagnoseResult:event.diagnoseResult,
        medicineList:event.medicineList,
        startDianoseTime:event.startDianoseTime,
        endDianoseTime:event.endDianoseTime,
        appointPay:event.appointPay,
        medicinePay:event.medicinePay,
        allPay:event.allPay,
        addInfo:event.addInfo,
        flowId:event.flowId,
      }
    }).then(res => {
      return res
    }).catch(res => {
      return res
    })
  } 
  else if (event.action == "find") {
    return await cloud.database().collection('diagnose').get()
      .then(res => {
        return res
      }).catch(res => {
        return res
      })
  }
  else if(event.action=="findOneByFlowId"){
    return await cloud.database().collection('diagnose').where({
      flowId:event.flowId
    }).get()
    .then(res => {
      return res
    }).catch(res => {
      return res
    })
  }
  else if(event.action=="changeAddInfoByFlowId"){
    return await cloud.database().collection('diagnose').where({
      flowId:event.flowId,
    }).update({
      data:{
        addInfo:event.addInfo
      }
    })
    .then(res => {
      return res
    }).catch(res => {
      return res
    })
  }
}